package com.jumi.microservice.controller.admin;

import com.jumi.microservice.common.base.BaseController;
import com.jumi.microservice.common.base.dto.ResponseResult;
import com.jumi.microservice.constant.compensation.AfterSaleStatusEnum;
import com.jumi.microservice.dto.afterseal.AfterSealCancelRequest;
import com.jumi.microservice.service.admin.AfterSealServiceImpl;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.Map;

/**
 * @author scw
 * @date 2020/9/26
 */
@Api(tags = {"售后订单管理--取消售后订单接口"})
@RestController
@RequestMapping("/admin/afterSeal")
public class AdminAfterSealController extends BaseController {
    @Resource
    AfterSealServiceImpl afterSealService;

    @PostMapping(value = "/cancelAfterSealOrder")
    @ApiOperation("售后订单取消")
    public ResponseResult<Boolean> cancelAfterSealOrder(@RequestBody  AfterSealCancelRequest request) {
        ResponseResult<Boolean> result = new ResponseResult<>();
        request.setOperatorId(getUid());
        request.setOperatorName(getUserName());
        result.setData(afterSealService.cancelAfterSealOrder(request));
        return result;
    }

    @GetMapping(value = "/status")
    @ApiOperation("售后状态字典")
    public ResponseResult<Map<Object,Object>> status() {
        AfterSaleStatusEnum[] afterSaleStatusEnums = AfterSaleStatusEnum.values();
        Map<Object,Object> map = new HashMap<>(afterSaleStatusEnums.length);
        for(AfterSaleStatusEnum afterSaleStatusEnum:afterSaleStatusEnums){
            if(afterSaleStatusEnum.getCode()==0){
                continue;
            }
            map.put(afterSaleStatusEnum.getCode(),afterSaleStatusEnum.getMsg());
        }
        return success(map);
    }

}
